//
//  Common.swift
//  goHomeSleep
//
//  Created by 沈家旭 on 16/6/28.
//  Copyright © 2016年 jiaxu. All rights reserved.
//

import Foundation
extension String{
    
    func md5() ->String!{
        let str = self.cStringUsingEncoding(NSUTF8StringEncoding)
        let strLen = CUnsignedInt(self.lengthOfBytesUsingEncoding(NSUTF8StringEncoding))
        let digestLen = Int(CC_MD5_DIGEST_LENGTH)
        let result = UnsafeMutablePointer<CUnsignedChar>.alloc(digestLen)
        CC_MD5(str!, strLen, result)
        let hash = NSMutableString()
        for i in 0 ..< digestLen {
            hash.appendFormat("%02x", result[i])
        }
        result.destroy()
        return String(format: hash as String)
    }
}
class CommonModel {
    /*
        字符串转换MD5
    */
    func md5(str: String) -> String{
        return str.md5();
    }
}